<!-- 信息 START -->
<nz-card>
  <nz-descriptions nzTitle="促销信息" nzBordered nzSize="small">
    <nz-descriptions-item nzTitle="促销ID">{{ detailInfoData.id }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="状态">
      <span [ngStyle]="{'color': detailInfoData.status | stateStatus: 'color'}">
        {{ detailInfoData.status | stateStatus: 'text' }}
      </span>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="创建时间">{{ detailInfoData.createTime || '-' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="活动名称" [nzSpan]="2">{{ detailInfoData.name || '-' }}</nz-descriptions-item>
    <nz-descriptions-item nzTitle="前端标题">{{ detailInfoData.showCopy || '-' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="使用门槛" *ngIf="[1, 2].includes(detailInfoData?.type)">订单满 {{ detailInfoData.orderLimitMoney || '0' }} 元可用</nz-descriptions-item>
    <nz-descriptions-item nzTitle="领取人限制">
      <nz-tag [nzColor]="'#2db7f5'" *ngIf="detailInfoData.userType == 2">B端</nz-tag>
      <nz-tag [nzColor]="'#87d068'" *ngIf="detailInfoData.userType == 1">C端</nz-tag>
      <nz-tag *ngIf="detailInfoData.userType == 0">通用</nz-tag>
    </nz-descriptions-item>
    <nz-descriptions-item nzTitle="有效时间">{{ detailInfoData.beginTime || '' }} ~ {{ detailInfoData.endTime || '' }}</nz-descriptions-item>

    <nz-descriptions-item nzTitle="活动类型">{{ detailInfoData?.type | activityTypeStatus }}</nz-descriptions-item>
    <ng-container *ngIf="detailInfoData.type == 1;else activityTypeTemplate">
      <nz-descriptions-item nzTitle="减免额度">{{ detailInfoData.limitSmall || '0' }}元</nz-descriptions-item>
      <nz-descriptions-item nzTitle="倍数减免">{{ detailInfoData.overlayFlag == 0 ? '否' : (detailInfoData.overlayFlag == 1 ? '是' : '-') }}</nz-descriptions-item>
    </ng-container>
    <ng-template #activityTypeTemplate>
      <nz-descriptions-item nzTitle="折扣力度" *ngIf="[1, 2].includes(detailInfoData?.type)">{{ detailInfoData.limitSmall || '0' }}折</nz-descriptions-item>
      <nz-descriptions-item nzTitle="最高减免" *ngIf="[1, 2].includes(detailInfoData?.type)">{{ detailInfoData.limitBig || '0' }}元</nz-descriptions-item>
    </ng-template>

    <nz-descriptions-item nzTitle="备注" [nzSpan]="3">{{ detailInfoData.remark || '-' }}</nz-descriptions-item>
  </nz-descriptions>
</nz-card>
<!-- 信息 END -->

<!-- S 多件折扣 -->
<nz-card class="m-t-2" *ngIf="detailInfoData?.discountTable && detailInfoData?.discountTable?.length">
  <div class="record-card-hd p-b-10">
    <label class="record-p">
      {{ detailInfoData?.type | activityTypeStatus }}
    </label>
  </div>

  <nz-table
    #multipleTable
    nzSize="small"
    nzBordered
    [nzFrontPagination]="false"
    [nzData]="detailInfoData?.discountTable">
    <thead>
      <tr>
        <th nzAlign="center">{{[3, 4].includes(detailInfoData?.type) ? '>=件数' : '>=金额'}}</th>
        <!-- 多件折扣3 or 阶梯折扣6 -->
        <ng-container *ngIf="[3, 6].includes(detailInfoData.type)">
          <th nzAlign="center">折扣率</th>
          <th nzAlign="center">最多减免</th>
        </ng-container>
        <!-- 多件立减4 or 阶梯满减5 -->
        <ng-container *ngIf="[4, 5].includes(detailInfoData.type)">
          <th nzAlign="center">减免</th>
        </ng-container>
      </tr>
    </thead>
    <tbody>
      <tr *ngFor="let data of multipleTable.data">
        <!-- 3，4件数、5，6金额 -->
        <td nzAlign="center">
          {{[3, 4].includes(detailInfoData.type) ? data.number : data.orderLimitMoney}}
        </td>
        <!-- 多件折扣3 or 阶梯折扣6 -->
        <ng-container *ngIf="[3, 6].includes(detailInfoData.type)">
          <td nzAlign="center">{{data.discountRate || '-'}}</td>
          <td nzAlign="center">{{data.maxReduction || '-'}}</td>
        </ng-container>
        <!-- 多件立减4 or 阶梯满减5 -->
        <ng-container *ngIf="[4, 5].includes(detailInfoData.type)">
          <td nzAlign="center">{{data.reduction || '-'}}</td>
        </ng-container>
      </tr>
    </tbody>
  </nz-table>
</nz-card>
<!-- E 多件折扣 -->

<!-- 使用记录 START -->
<nz-card class="record-card-wrap m-t-2">
  <div class="record-card-hd">
    <label class="record-p">使用记录</label>
    <nz-select nzShowSearch nzAllowClear nzPlaceHolder="全部订单状态" [(ngModel)]="tableForms.status" (ngModelChange)="orderStateChange($event)">
      <nz-option
        *ngFor="let item of orderStateOptions | keyvalue"
        nzLabel="{{ item.value }}"
        nzValue="{{ item.key }}">
      </nz-option>
    </nz-select>
  </div>
  
  <!-- Table -->
  <div class="table-wrap">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzBordered
      [nzScroll]="{ x: '1000px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableForms.tableLoading"
      [nzData]="tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableForms.total"
      [nzPageIndex]="tableForms.page"
      [nzPageSize]="tableForms.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)">
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="180px" nzLeft>订单编号</th>
          <th nzAlign="center" nzWidth="140px">订单状态</th>
          <th nzAlign="center">用户ID</th>
          <th nzAlign="center">应付金额</th>
          <th nzAlign="center">实付金额</th>
          <th nzAlign="center">优惠总额</th>
          <th nzAlign="center">本优惠抵值</th>
          <th nzAlign="center" nzWidth="180px">下单时间</th>
          <th nzAlign="center" nzWidth="180px">付款时间</th>
          <th nzAlign="center" nzWidth="200px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data">
          <td nzAlign="center" nzLeft>{{ data.orderNum || '-' }}</td>
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | orderColorStatus}">
              {{ data.status | orderStateStatus }}
            </span>
          </td>
          <td nzAlign="center">
            <a nz-button nzType="link" nzSize="small" [routerLink]="['/customer/tabs', data.userId, 0]" target="_blank">{{ data.userId }}</a>
          </td>
          <td nzAlign="center">{{ data.totalPrice || '0' }}</td>
          <td nzAlign="center">{{ data.realPrice || '0' }}</td>
          <td nzAlign="center">{{ data.favorablePrice || '0' }}</td>
          <td nzAlign="center">{{ data.discountValue || '0' }}</td>
          <td nzAlign="center">{{ data.orderTime || '-' }}</td>
          <td nzAlign="center">{{ data.payTime || '-' }}</td>
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzType="link"
              (click)="openModel(data)">
              跟进订单
            </button>
            <button
              *ngIf="(data.status == 5 || data.status == 6 || data.status == 7) && permission.userPermission.has('marketing:descentRecord:cancel')"
              nz-button
              nzType="link"
              nzDanger
              (click)="cannlOrder(data)">
              取消订单
            </button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ tableForms.total }} 条</ng-template>
  </div>
</nz-card>
<!-- 使用记录 END -->

<!-- 跟进model -->
<app-followup-model #myFollowup [oddNumber]="oddNumber" (deterMine)="submitData($event)"></app-followup-model>